package com.yanq.liancar.address_selection.adapter;
/*
 *  @创建者     Administrator
 *  @创建时间   2018/11/6  10:12
 *  @描述       ${TODO}
 */


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yanq.liancar.R;

import java.util.ArrayList;
import java.util.List;

public class HotCityGridAdapter extends BaseAdapter {

    private Context mContext;

    private List<String> mCities;



    public HotCityGridAdapter(Context context) {

        this.mContext = context;

        mCities = new ArrayList<>();

        mCities.add("温州");

        mCities.add("杭州");

        mCities.add("舟山");

        mCities.add("台州");

        mCities.add("衢州");

        mCities.add("宁波");

        mCities.add("北京");

        mCities.add("上海");

        mCities.add("广州");

    }



    @Override

    public int getCount() {

        return mCities == null ? 0 : mCities.size();

    }



    @Override

    public String getItem(int position) {

        return mCities == null ? null : mCities.get(position);

    }



    @Override

    public long getItemId(int position) {

        return position;

    }



    @Override

    public View getView(int position, View view, ViewGroup parent) {

        HotCityViewHolder holder;

        if (view == null){

            view = LayoutInflater.from(mContext).inflate(R.layout.item_hot_city_gridview, parent, false);

            holder = new HotCityViewHolder();

            holder.name = (TextView) view.findViewById(R.id.tv_hot_city_name);

            view.setTag(holder);

        }else{

            holder = (HotCityViewHolder) view.getTag();

        }

        holder.name.setText(mCities.get(position));

        return view;

    }



    public static class HotCityViewHolder{

        TextView name;

    }
}
